//
//  CALayer+Extension.m
//  动画测试
//
//  Created by 盛青 on 16/4/18.
//  Copyright © 2016年 孟祥京. All rights reserved.
//

#import "CALayer+Extension.h"

@implementation CALayer (Extension)
+ (void)applyBasicAnimation:(CABasicAnimation *)animation toLayer:(CALayer *)layer{
    
    //set the from value (using presentation layer if available)
    animation.fromValue = [layer.presentationLayer ?: layer valueForKeyPath:animation.keyPath];
    //update the property in advance
    //note: this approach will only work if toValue != nil
    [CATransaction begin];
    [CATransaction setDisableActions:YES];
    [layer setValue:animation.toValue forKeyPath:animation.keyPath];
    [CATransaction commit];
    //apply animation to layer
    [layer addAnimation:animation forKey:nil];
}
@end
